From a97bedb2120eb5b277eb5a9cca85f4e659c17cbe Mon Sep 17 00:00:00 2001 From: Julien Grall Date: Wed, 20 Jul 2016 17:10:50 +0100 Subject: [PATCH] xen/arm: p2m: Simplify p2m type check by using bitmask The resulting assembly code for the macros is much simpler and will never contain more than one instruction branch. The idea is taken from x86 (see include/asm-x86/p2m.h). Also move the two helpers earlier to keep all the p2m type definitions together. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- xen/include/asm-arm/p2m.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index dbbcefe326..3091c049b7 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -97,6 +97,17 @@ typedef enum { p2m_max_real_type, /* Types after this won't be store in the p2m */ } p2m_type_t; +/* We use bitmaps and mask to handle groups of types */ +#define p2m_to_mask(_t) (1UL << (_t)) + +/* RAM types, which map to real machine frames */ +#define P2M_RAM_TYPES (p2m_to_mask(p2m_ram_rw) | \ + p2m_to_mask(p2m_ram_ro)) + +/* Useful predicates */ +#define p2m_is_ram(_t) (p2m_to_mask(_t) & P2M_RAM_TYPES) +#define p2m_is_foreign(_t) (p2m_to_mask(_t) & p2m_to_mask(p2m_map_foreign)) + static inline void p2m_mem_access_emulate_check(struct vcpu *v, const vm_event_response_t *rsp) @@ -110,9 +121,6 @@ void p2m_altp2m_check(struct vcpu *v, uint16_t idx) /* Not supported on ARM. */ } -#define p2m_is_foreign(_t) ((_t) == p2m_map_foreign) -#define p2m_is_ram(_t) ((_t) == p2m_ram_rw || (_t) == p2m_ram_ro) - /* Initialise vmid allocator */ void p2m_vmid_allocator_init(void); -- 2.30.2